package com.yiboshi.rehrs.util.xsd;

import com.alibaba.fastjson.JSONObject;
import com.yiboshi.rehrs.util.JSONBuilder;
import com.yiboshi.rehrs.util.MD5;
import com.yiboshi.rehrs.util.OkHttpUtil;

import java.security.PublicKey;
import java.security.Security;

public class EncodeUtils {


//     ArrayMap arrayMap = new ArrayMap();
//     ArrayMap arrayMap2 = arrayMap;
//     arrayMap2.put("Api", "92b8df24ee0d966b782b7ec9df488a16");
//     arrayMap2.put("Time", Long.valueOf(currentTimeMillis));
//     arrayMap2.put("Status", Integer.valueOf(Integer.parseInt((String) objectRef.element)));
//     String generateRandomString = AESUtilNewYz.generateRandomString(24);
//     String encrypt = AESUtilNewYz.encrypt(GsonUtils.INSTANCE.toJson(arrayMap), generateRandomString);
//     String encrypt2 = RSAUtils.encrypt(generateRandomString, RSAUtils.getPublicKeyFromString(AppManager.gongYao));
//     ArrayMap arrayMap3 = new ArrayMap();
//     ArrayMap arrayMap4 = arrayMap3;
//     arrayMap4.put("a", encrypt);
//     arrayMap4.put("b", encrypt2);
//     OkHttpUtils.postString().url(AppManager.INSTANCE.getBASE_URL_NEW()).addHeader(HttpConnection.CONTENT_TYPE, "application/json").addHeader("Accept", "application/json, text/plain, */*").addHeader("Accept-Language", "zh-CN,zh;q=0.9").addHeader("Cache-Control", "no-cache").addHeader("Pragma", "no-cache").addHeader("Token", SharedPreferencesManager.INSTANCE.loadString(SharedPreferencesManager.tokenYz, "")).addHeader("User-Agent", System.getProperty("http.agent")).content(GsonUtils.INSTANCE.toJson(arrayMap3)).mediaType(MediaType.parse("application/json")).build().execute(new StringCallback() { // from class: com.xsd.ems.MainActivity.GetVipData.1


    //String decrypt = AESUtilNewYz.decrypt(abBean.getA(), RSAUtils.decryptWithPublicKey(abBean.getB(), RSAUtils.getPublicKeyFromString(AppManager.gongYao)));
    public static final String VERSION_NAME = "1.4.1";

    public static void loginDecode(String[] args) throws Exception {
        //Security.setProperty("crypto.policy", "unlimited");

//https://211.156.197.65/pdalogin/p/common/loginbyusrface
        String a = "";
        String b = "";
        PublicKey publicKeyFromString = null;
        String s = "";
        String decrypt = "";
        //请求
//       a = "YxcuFuaHtsSTEoLM+nhDI4/4RaGUAFflKG4EnR5zNEw9AaRu/nbk/Y8kRE7UXtz8uJ/MLwHdZECNmOYJaT7kaZcwV/vt/9pg3eFxHlCVqEadnKehRGhZABE2CQXs+4ZTjpRVIKn6NR5Ro1RM17BfbxcnLQhseUi6jkJh3YK8vkEPCL+xcQPkM/DWg3ZnBRU6vTSsZxjaRA0ew+NuJJK4GSyZVoCDREvLEJA1SNeYoGGrJR3JpBlZ0L70/CoFLxYUjbYZ/BAfU6h+qKocMq0CIQ==";
//         b = "L1UlLULOnDO0ZELTxOO9dKQWTfgnMFpcFSv0qnibNbvU4tNWEtGvmTMWDDGayfzJi0ThuKigK2kFsxz8T5C42VTGs4zObho7qlO5IJY9XR1OOySN8TgH9mR4IIbnWwewJ+6gYtxoSRRG+yfmzWNd36Y1/MXHH2m5YIuKe6+oZZ0=";
//        publicKeyFromString = RSAUtils.getPublicKeyFromString(AESUtilNewYz.gongYao);
//        s = RSAUtils.decryptWithPublicKey(b, publicKeyFromString);
//        decrypt = AESUtilNewYz.decrypt(a, s);
//        System.out.println(decrypt);
        //{"Data":{"Token":"KLLPWTWN8VY0K9JRXNXCGNNFXFKWD4IT","CryptoKeyAes":"yzA84K9N4JAYLD0qHZpWLBJr","IP":"117.176.187.72"},"Time":1755507718,"Status":35637,"Msg":""}

        a = "lZGwapV/KHtBCZM3iF3kv+tTyNTMCBJrYY7ZWW9xvSMFLpBkzrZ4sp8GWqtVoYEYUpVtPRZE1ufAI5bF3rC+Rw==";
        b="Nx3qro9Zg02Zkwm4KsBSe7ogXBiNd5xjuuWsAG9A622KG1PSzv5iV8AX7HVs6ZriBlFqJGGZpziNfclc0hcYNv3xwy+5zkoVJbSFSm/6TKvdUWuvdY4J6W4v4VhSN4rz5VC8g00YWHAM1AWww/3FQICVh+re57QQsZMdTviZOho=";
        publicKeyFromString = RSAUtils.getPublicKeyFromString(AESUtilNewYz.gongYao);
        s = RSAUtils.decryptWithPublicKey(b, publicKeyFromString);
        decrypt = AESUtilNewYz.decrypt(a, s);
        System.out.println(decrypt);


        String CryptoKeyAes = "yzA84K9N4JAYLD0qHZpWLBJr";




    }

    public static void main(String[] args) throws Exception {
        String a = "a=wfiE/Yur7/XiTuAXYtCVH9GsmX7qN+HRzZaPGWIKxtDM/iakpDWEs82bExBE/dNB";//{"Time":1755566955,"Status":20994,"Msg":""}
        decode(a);
        a = "a=wfiE/Yur7/XiTuAXYtCVH9fsWU5r2g8k+smRLH1zpWZ38XVSaD4UJ84EpOlR+dKM5li/GJpeylNUe3aXbVnLuA==";//{"Time":1755566955,"Status":38164,"Msg":"注册成功"}
        decode(a);

       a = "a=Ztoc1UgaLjEAU2qx1CeESZOQhtzEsr9CaDGaegnVb57j8DqvnPi/d+T/IaF23jQ+OHD6gZhIXt/vlEELmBG5FTzYWU0xKPJMYqcMOiPuq7W/x8/Ts7sRp3fN2RvXTl42cY0SFDKihfK2X0Tmr/kaHGCiBKui3zFErFBvtW5X20DXjfXitN8k6xwaouEo/EHRdYs5Fy0Q2FtzKTv/m9FpkdT6qmmV0dgq9oduQEEgby88Zc88yXgu8r/KTVVLL4aN5ZYyIAvNQFqVYKDgRGc6jw==";
      //{"Data":[{"Id":3,"Money":80,"Name":"小时代30天","NoUserClass":1,"UserClassId":2,"UserClassMark":1,"UserClassName":"VIP用户","UserClassWeight":1}],"Time":1755566955,"Status":17912,"Msg":""}
       decode(a);

        String CryptoKeyAes = "yzA84K9N4JAYLD0qHZpWLBJr";

        //{"Data":{"Token":"459LNTFQUUKQFNEQJNFFBGHZPZLK038U","CryptoKeyAes":"yzA84K9N4JAYLD0qHZpWLBJr","IP":"117.176.187.72"},"Time":1755576849,"Status":21542,"Msg":""}
        //String token = getToken();
        //String login = login("2153011500017", "459LNTFQUUKQFNEQJNFFBGHZPZLK038U");
        //System.out.println(login);

        String getHeader = getHeader("/pdalogin/p/common/loginbyusrsms", CryptoKeyAes,"459LNTFQUUKQFNEQJNFFBGHZPZLK038U");
        System.out.println(getHeader);


    }

   static  String CryptoKeyAes = "yzA84K9N4JAYLD0qHZpWLBJr";
    public static void vipDecode(String[] args) throws Exception {
        String token = getToken();

    }

    public static String  decode(String a,String b) throws Exception {
        PublicKey publicKeyFromString = RSAUtils.getPublicKeyFromString(AESUtilNewYz.gongYao);
       String s = RSAUtils.decryptWithPublicKey(b, publicKeyFromString);
        return  AESUtilNewYz.decrypt(a, s);
    }

    public static String  decode(String a) throws Exception {
        if(a.startsWith("a=")){
            a = a.substring(2);
        }
        String decrypt = AESUtilNewYz.decrypt(a, CryptoKeyAes);
        System.out.println(decrypt);
        return decrypt;
    }




    //返回{"Data":{"Token":"YBEQCNN8FVQPAKRYNJHM8TAXPDV6GGFW","CryptoKeyAes":"yzA84K9N4JAYLD0qHZpWLBJr","IP":"117.176.187.72"},"Time":1755512398,"Status":42290,"Msg":""}
    public static String getToken() throws Exception {
        String rando99999 = setRando99999();
        long currentTimeMillis = System.currentTimeMillis() / 1000;

        JSONObject end = JSONBuilder.start("Api", "b003a2188e329355765ae0c7a2aa293d")
                .put("Time", currentTimeMillis).put("Status", Integer.valueOf(rando99999)).end();
        String generateRandomString = AESUtilNewYz.generateRandomString(24);
        String encrypt = AESUtilNewYz.encrypt(end.toJSONString(), generateRandomString);
        String encrypt2 = RSAUtils.encrypt(generateRandomString, RSAUtils.getPublicKeyFromString(AESUtilNewYz.gongYao));

        JSONObject end2 = JSONBuilder.start("a", encrypt).put("b", encrypt2).end();
        String data = end2.toJSONString();
        String execute = new OkHttpUtil().post(data)
                .url("https://xsd.taety.cn/Api?AppId=10001").execute();
        JSONObject jsonObject = JSONObject.parseObject(execute);
        String a = jsonObject.getString("a");
        String b = jsonObject.getString("b");
        PublicKey publicKeyFromString = RSAUtils.getPublicKeyFromString(AESUtilNewYz.gongYao);
        String s = RSAUtils.decryptWithPublicKey(b, publicKeyFromString);
        String decrypt = AESUtilNewYz.decrypt(a, s);
        return decrypt;
    }

    public static String login(String person_no,String token) throws Exception {
        String rando99999 = setRando99999();
        long currentTimeMillis = System.currentTimeMillis() / 1000;

        JSONObject end = JSONBuilder
                .start("Api", "880fde0af62f49571e4d797799f98ee5")
                .put("Time", currentTimeMillis)
                .put("Status", Integer.valueOf(rando99999))
        .put("UserOrKa", person_no)
        .put("PassWord", person_no)
        .put("Key", person_no)
        .put("Tab", "暂时没有动态标记")
        .put("AppVer", VERSION_NAME)
        .put("Time", Long.valueOf(currentTimeMillis))
        .put("Status", Integer.valueOf(Integer.parseInt((rando99999))))
                .end();
        String generateRandomString = AESUtilNewYz.generateRandomString(24);
        String encrypt = AESUtilNewYz.encrypt(end.toJSONString(), generateRandomString);
        String encrypt2 = RSAUtils.encrypt(generateRandomString, RSAUtils.getPublicKeyFromString(AESUtilNewYz.gongYao));

        JSONObject end2 = JSONBuilder.start("a", encrypt).put("b", encrypt2).end();
        String data = end2.toJSONString();
        String execute = new OkHttpUtil().post(data)
                .addHeader("token", token)
                .url("https://xsd.taety.cn/Api?AppId=10001").execute();
        JSONObject jsonObject = JSONObject.parseObject(execute);
        String a = jsonObject.getString("a");
        String b = jsonObject.getString("b");
        PublicKey publicKeyFromString = RSAUtils.getPublicKeyFromString(AESUtilNewYz.gongYao);
        String s = RSAUtils.decryptWithPublicKey(b, publicKeyFromString);
        String decrypt = AESUtilNewYz.decrypt(a, s);
        return decrypt;
    }




    public static String getHeader(String path,String CryptoKeyAes,String token) throws Exception {
        String rando99999 = setRando99999();
        long currentTimeMillis = System.currentTimeMillis() / 1000;
        JSONObject Parameter = JSONBuilder.start("VipTime", currentTimeMillis+100)
                .put("path", "path="+path).end();
        JSONObject end = JSONBuilder.start("Api", "47fa75de0d3e2792e9df4c386a4e994d")
                .put("Parameter",Parameter.toJSONString())
                .put("JsName","功能")
                .put("IsGlobal","false")
                .put("Time", currentTimeMillis)
                .put("Status", Integer.valueOf(rando99999))
                .end();

        //
//        String encrypt = AESUtilNewYz.encrypt(GsonUtils.INSTANCE.toJson(arrayMap), SharedPreferencesManager.INSTANCE.loadString(SharedPreferencesManager.CryptoKeyAes, ""));
//        String md5 = UIUtil.md5(Intrinsics.stringPlus(encrypt, SharedPreferencesManager.INSTANCE.loadString(SharedPreferencesManager.CryptoKeyAes, "")));
//        ArrayMap arrayMap3 = new ArrayMap();
//        ArrayMap arrayMap4 = arrayMap3;
//        arrayMap4.put("a", encrypt);
//        arrayMap4.put("b", md5);
        String encrypt = AESUtilNewYz.encrypt(end.toJSONString(), CryptoKeyAes);
        String md5 = MD5.encode(encrypt + CryptoKeyAes);
        JSONObject end2 = JSONBuilder.start("a", encrypt).put("b", md5).end();
        String data = end2.toJSONString();
        //data = "{\"a\":\"GvhVQXNwhVTQ/Db3Qb3cr3XKGsDD0bDO4h+V3A0EGzUAdelnrOhwqDqU2QB9zPMY8PyPa4y/iAj23W2hNxT18lFEmXvrbWdveNBFSoju7MGXrvo7mYUrcZBie5rwR0fkHZqmuyzM/VbCZNpEKr9o9FzIkxdw90dcImyVXarodEKNDthXfUnZH3C3RFel1iGjVGxPYxeLCeLfdMgfP7kcUpJHJSx5/A+qtBuYd6WIuZpVmAkFdZ+orRiDyxtjnzakePQSx4fibc3Czs4iSOvYR9N/J4VNeDW5/7m41In46lo=\",\"b\":\"42625863b68b53ad539d2ea48ce0589d\"}";
        String execute = new OkHttpUtil().post(data)
                .addHeader("Content-Type", "application/json; charset=utf-8")
                .addHeader("Accept","application/json, text/plain, */*")
                .addHeader("User-Agent:","Dalvik/2.1.0 (Linux; U; Android 10; AQM-AL10 Build/HONORAQM-AL10)")
                .addHeader("Token",token)
                .url("https://xsd.taety.cn/Api?AppId=10001")
                .execute();
        JSONObject jsonObject = JSONObject.parseObject(execute);
        System.out.println(jsonObject);
        String a = jsonObject.getString("a");
        String decrypt = AESUtilNewYz.decrypt(a, CryptoKeyAes);
        return decrypt;

    }


    public static final String setRando99999() {
        return String.valueOf(((int) (Math.random() * 89991)) + 10009);
    }

}
